<?php
/**
* Desc
*
* @link http://webappkit.net
* @package pathnodes
* @subpackage xml
* @author J.Ducastel <jeremie@ducastel.name>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

/**
* registers as pathnode
*/
pathnode::heritage('xmlfilenode',20);

/**
*
* @uses
*/
class xmlFileNode extends textFileNode {
/*--------------------------------------------------------------------
CONSTRUCTOR
--------------------------------------------------------------------*/
	/**
	* constructor alias
	* @access public
	* /
	function xmlFileNode($path=null) {
		$this->__construct($path);
	}/**/
	
	/**
	* "real" constructor
	* @access public
	* /
	function __construct($path=null) {
		parent::__construct($path);
	}/**/
/*--------------------------------------------------------------------
PUBLIC STATIC METHODS
--------------------------------------------------------------------*/
	/**
	* required for pathnode::getnode()
	*/
	function selfDetector($path) {
		return ereg('\.xml$',$path);
	}/**/
	
	/**
	* 
	* @static
	* @param
	* @return 
	* /
	function () {
		
	}/**/
/*--------------------------------------------------------------------
PUBLIC INSTANCE METHODS
--------------------------------------------------------------------*/
	/**
	* sets domDocument
	* @access public
	* @param mixed $source either domDocument instance or xml string
	* if null, will tries to load from file content
	* @return bool
	* @todo allowing >10Mo files ? (filenode->read default max)
	* @todo auto-registering namespace prefixes
	*/
	function setDocument($source=null) {
		switch (true) {
			case is_string($source):
			case is_a($source,'domdocument'):
			case $source=$this->read():
				$class=$this->_documentClass();
				$this->doc=&new $class($source);
		}
		if ($this->doc->isValid()) {
			// success
			// setting namespaces
			$this->_setNamespaces();
			return true;
		}
		return false;
	}

	/**
	* returns domDocument instance
	* @access public
	* @return domDocument
	*/
	function & getDocument() {
		// building document if not done
		if (!$this->doc and !$this->setDocument()) {
			return false;
		}
		return $this->doc->getNode();
	}/**/
	
	/**
	* searches for nodes targeted by xpath
	* @param string $xpath
	* @access public
	* @return array domNode instances
	*/
	function searchNodes($xpath) {
		// building document if not done
		if (!$this->doc and !$this->setDocument()) {
			return false;
		}
		return $this->doc->searchNodes($xpath);
	}/**/
	
	/**
	* searches for nodes' content targeted by xpath
	* @param string $xpath
	* @access public
	* @return array domNode instances or strings
	*/
	function searchContent($xpath) {
		// building document if not done
		if (!$this->doc and !$this->setDocument()) {
			return false;
		}
		return $this->doc->searchContent($xpath);
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	*/
	function registerNamespace($prefix,$uri) {
		// building document if not done
		if (!$this->doc and !$this->setDocument()) {
			return false;
		}
		return $this->doc->registerNamespace($prefix,$uri);
	}/**/
	
	/**
	* is a valid xml document file ?
	* @access public
	* @return bool
	*/
	function isValid() {
		// building document if not done
		if (!$this->doc and !$this->setDocument()) {
			return false;
		}
		// checking
		return $this->doc->isValid();
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
/*--------------------------------------------------------------------
VARS / MEMBERS
--------------------------------------------------------------------*/
	/**
	* @var xpathDomNode domDocument encapsulated
	*/
	var $doc;
	
	/**
	* @var array namespaces to declare : prefix => uri
	*/
	// var $namespaces=array();
/*--------------------------------------------------------------------
PRIVATE / PROTECTED METHODS
--------------------------------------------------------------------*/
	/**
	* will be called by setDocument
	* @access protected
	* @return bool
	* @todo auto-set the root namespace uri
	*/
	function _setNamespaces() {
		return true;
	}/**/
	
	/**
	* returns document class to build. Musts inherit xpathdomnode
	* @access protected
	* @return string
	*/
	function _documentClass() {
		return 'xpathdomnode';
	}/**/
	
	/**
	* 
	* @param
	* @access protected
	* @return 
	* /
	function () {
		
	}/**/
}
?>
